<template>
    <div class="wedding-invitation" :class="{ 'invitation-bounce': canOpen }">
        <div
            class="invitation-container"
            :class="{ 'invitation-down': isOpening }"
        >
            <div class="invitation-cover">
                <div
                    class="cover-content"
                    :class="{ 'invitation-up': isOpening }"
                >
                    <div class="content-inside">
                        <img
                            class="content-inside-photo"
                            src="../assets/images/photo.png"
                        />
                        <p>我们结婚啦！</p>
                        <p>
                            <b>{{ marry.name }}</b>
                        </p>
                        <p>时间：{{ marry.time }}</p>
                        <p>
                            地点：<b>{{ marry.address }}</b>
                        </p>
                        <div class="content-inside-bless">
                            <input
                                placeholder="写下你的祝福"
                                @keyup.enter="sendBarrage"
                                v-model="wish"
                            />
                            <div>
                                <button @click="sendBarrage">
                                    发送祝福弹幕
                                </button>
                                <button @click="closeInvitation">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div
                    class="cover-inside-left"
                    :class="{ opening: isOpening }"
                ></div>
                <div
                    class="cover-inside-right"
                    :class="{ opening: isOpening }"
                ></div>
                <img
                    class="cover-inside-seal"
                    src="../assets/images/seal.png"
                    @click="openInvitation"
                    v-show="!isOpening"
                    :class="{ 'invitation-flight': isOpening }"
                />
            </div>
        </div>
    </div>
</template>

<script setup>
import { defineProps, ref, defineEmits, nextTick } from "vue";
import { marry } from "../mock/data";
defineProps({
    canOpen: {
        type: Boolean,
        default: true,
    },
});
const isOpening = ref(false);
const wish = ref("");
const $emit = defineEmits(["onClose", "sendBarrage"]);
// 打开邀请函
const openInvitation = () => {
    isOpening.value = true;
    wish.value = "";
};
// 关闭邀请函
const closeInvitation = () => {
    isOpening.value = false;
    setTimeout(() => {
        $emit("onClose"); // 发送事件父元素
    }, 660);
};
// 发送祝福语
const sendBarrage = () => {
    nextTick(() => {
        if (!wish.value) return;
        isOpening.value = false;
        setTimeout(() => {
            $emit("sendBarrage", wish.value);
        }, 660);
    });
};
</script>

<style lang="less">
.wedding-invitation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 50px 40px;
    z-index: 4;
    transform: scale(0.05);
    opacity: 0;
    transition: transform 0.8s cubic-bezier(0.26, 1.84, 0.39, 0.61),
        opacity 0.5s linear;
    background-size: 100%;
    overflow: hidden;
    &.invitation-bounce {
        opacity: 1;
        transform: scale(1);
    }
    .invitation-container {
        position: relative;
        width: 100%;
        height: 100%;
        transition: transform 0.6s cubic-bezier(0.4, 0, 1, 1);
        &.invitation-down {
            transform: translateY(20px);
        }
        .invitation-cover {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #d65047;
            border-radius: 10px;
            perspective: 500px;
            box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.15);
            .cover-content {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                padding: 10px 20px;
                transition: transform 0.6s cubic-bezier(0.4, 0, 1, 1);
                &.invitation-up {
                    transform: translateY(50px);
                }
                .content-inside {
                    height: 100%;
                    padding: 20px;
                    color: #a9895d;
                    background-color: #fff1de;
                    text-align: center;
                    overflow: auto;
                    .content-inside-photo {
                        width: 100%;
                        margin-bottom: 10px;
                        padding: 5px;
                        border: 1px solid #f7debb;
                    }
                    p {
                        margin-top: 0;
                        margin-bottom: 5px;
                    }
                    .content-inside-bless {
                        input {
                            width: 100%;
                            height: 35px;
                            margin-bottom: 10px;
                            outline: none;
                            border: none;
                            border-bottom: 1px solid #f7debb;
                            color: #a9895d;
                            background: transparent;
                            font-size: 16px;
                            &::-webkit-input-placeholder {
                                color: #e8d1b1;
                                font-size: 12px;
                            }
                            &::-moz-placeholder {
                                color: #e8d1b1;
                                font-size: 12px;
                            }
                            &:-ms-input-placeholder {
                                color: #e8d1b1;
                                font-size: 12px;
                            }
                            &:-moz-placeholder {
                                color: #e8d1b1;
                                font-size: 12px;
                            }
                        }
                        > div {
                            display: flex;
                            button {
                                width: 100%;
                                height: 35px;
                                color: #a9895d;
                                background: #f7debb;
                                border: none;
                                outline: none;
                                &:disabled {
                                    opacity: 0.8;
                                }
                                &:first-child {
                                    margin-right: 10px;
                                    flex: 1;
                                }
                                &:last-child {
                                    width: 60px;
                                    border: 1px solid #f7debb;
                                    background: transparent;
                                }
                            }
                        }
                    }
                }
            }
            .cover-inside-left {
                position: absolute;
                left: 0;
                top: 0;
                width: 70%;
                height: 100%;
                border-radius: 10px;
                background-color: #d65047;
                box-shadow: 5px 0 10px rgba(0, 0, 0, 0.2);
                z-index: 6;
                transition: transform 0.5s;
                transform-origin: 0 50%;
                &.opening {
                    transform: rotate3d(0, 1, 0, -140deg);
                }
            }
            .cover-inside-right {
                position: absolute;
                right: 0;
                top: 0;
                width: 40%;
                height: 100%;
                border-radius: 10px;
                background-color: #d65047;
                box-shadow: -5px 0 10px rgba(0, 0, 0, 0.2);
                z-index: 5;
                transition: transform 0.5s;
                transform-origin: 100% 50%;
                &.opening {
                    transform: rotate3d(0, 1, 0, 140deg);
                }
            }
            .cover-inside-seal {
                position: absolute;
                left: 70%;
                bottom: 100px;
                width: 80px;
                height: 80px;
                margin-left: -40px;
                z-index: 7;
                transform-origin: 50% 50%;
                transition: all 0.8s cubic-bezier(0.4, 0, 1, 1);
                cursor: pointer;
                &.invitation-flight {
                    opacity: 0;
                }
            }
        }
    }
}
</style>
